$(function(){//toFixed
	showCondition(true, 1, 1, 1, [0, 0, 1, 1, 1,1]);//加载查询条件
	//指标配置,后面走配置方法
	var quotass = [
				  {quotaCode_1:"CMI", quotaName_1:"CMI值", quotaCode_2:"DRGCount", quotaName_2:"DRGs组数",quotaCode_3:'TotalWeight'},//添加总权重 用于求散点图点的大小
				  {quotaCode_1:"TimeEff", quotaName_1:"时间消耗指数", quotaDirection_1:-1, quotaCode_2:"FeeEff", quotaName_2:"费用消耗指数", quotaDirection_2:-1,quotaCode_3:'TotalWeight'},//添加总权重 用于求散点图点的大小
	              {quotaCode_1:"AvgDays", quotaName_1:"平均住院日", quotaDirection_1:-1, quotaCode_2:"AvgFee", quotaName_2:"次均费用", quotaDirection_2:-1,quotaCode_3:'TotalWeight'},
	              {quotaCode_1:"AvgFee", quotaName_1:"次均费用", quotaDirection_1:-1, quotaCode_2:"DrugRatio", quotaName_2:"药占比", quotaDirection_2:-1,quotaCode_3:'TotalWeight'}
	              ];
	//初始化查询条件
	compareType = $("#searchcq").children().eq(3).find("a.active").attr("data-value");
	//如果比较类型为无，则环比幅度变化的按钮不显示
	if(compareType=='none'){
		$("#"+tabId+" .btnslider").fadeOut();
	}
	else{
		$("#"+tabId+" .btnslider").fadeIn();
	}
	var desc="超标";//控制显示达标还是超标的变量
	for(var o in quotass){
		var str;
		if(quotass[o].quotaCode_2=="DRGCount"){
			desc="达标";
		}else{
			desc="超标";
		}
		if(o==0){
			str = $('<li role="presentation" class="quotasTab active" style="margin-right: 20px;">'
					+'<a href="#depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'" role="tab" data-index='+o+' data-toggle="tab">'+quotass[o].quotaName_1+'和'+quotass[o].quotaName_2+'</a>'	
					+'</li>');
			str.appendTo($("#"+tabId+" #quota2Select"));
			$('<div role="tabpanel" class="tab-pane active" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'">'
				+'	<div class="col-xs-12" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-chart" style="height: 400px ;padding: 10px 10px;"></div>'
				+' <div class="col-xs-12" style="padding: 10px 10px;"><table id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table" class="table table-striped" style="border: solid 1px #ccc;"><tr><td style="width:10%">第一象限<br>(均'+desc+')</td><td></td></tr><tr><td>第二象限<br>('+quotass[o].quotaName_2+desc+')</td><td></td></tr><tr><td>第三象限<br>(均未'+desc+')</td><td></td></tr><tr><td>第四象限<br>('+quotass[o].quotaName_1+desc+')</td><td></td></tr></table><div>'
				+'</div>').appendTo($("#"+tabId+" #quota2SelectContent"))
		}else{
			if(compareType=='none'){
				str = $('<li role="presentation" class="quotasTab" style="margin-right: 20px;">'
						+'<a href="#depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'" role="tab" data-index='+o+' data-toggle="tab">'+quotass[o].quotaName_1+'和'+quotass[o].quotaName_2+'</a>'	
						+'</li>');
				str.appendTo($("#"+tabId+" #quota2Select"))
				$('<div role="tabpanel" class="tab-pane" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'">'
					+'	<div class="col-xs-12" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-chart" style="width: 1200px; height: 400px"></div>'
					+'  <div class="col-xs-12"><table id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table" class="table table-striped" style="border: solid thin black"><tr><td style="width:11%">第一象限<br>(均大于1)</td><td></td></tr><tr><td>第二象限<br>('+quotass[o].quotaName_2+'大于1)</td><td></td></tr><tr><td>第三象限<br>(均小于1)</td><td></td></tr><tr><td>第四象限<br>('+quotass[o].quotaName_1+'大于1)</td><td></td></tr></table><div>'
					+'</div>').appendTo($("#"+tabId+" #quota2SelectContent"))
			}else{
				str = $('<li role="presentation" class="quotasTab" style="margin-right: 20px;">'
						+'<a href="#depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'" role="tab" data-index='+o+' data-toggle="tab">'+quotass[o].quotaName_1+'和'+quotass[o].quotaName_2+'</a>'	
						+'</li>');
				str.appendTo($("#"+tabId+" #quota2Select"))
				$('<div role="tabpanel" class="tab-pane" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'">'
						+'	<div class="col-xs-12" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-chart" style="height: 400px;padding: 10px 10px;"></div>'
						+'  <div class="col-xs-12" style="padding: 10px 10px;"><table id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table" class="table table-striped" style="border: solid  1px #ccc;"><tr><td style="width:10%">第一象限<br>(均'+desc+')</td><td></td></tr><tr><td>第二象限<br>('+quotass[o].quotaName_2+desc+')</td><td></td></tr><tr><td>第三象限<br>(均未'+desc+')</td><td></td></tr><tr><td>第四象限<br>('+quotass[o].quotaName_1+desc+')</td><td></td></tr></table><div>'
						+'</div>').appendTo($("#"+tabId+" #quota2SelectContent"))
			}
		}
		//如果比较类型为无，则页面底部的科室象限分布表格不显示
		if(compareType=='none' && quotass[o].quotaCode_1!='TimeEff' && quotass[o].quotaCode_2!='FeeEff'){
			$('#'+tabId+' #depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table').fadeOut();
		}
		else{
			$('#'+tabId+' #depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table').fadeIn();
		}
		//tab页签点击事件
		str.find("a").bind("click", function(){
			var index = $(this).attr("data-index");
			var quotas = quotass[index];
			if(quotas.chartType==0){
				$("#"+tabId+" .btnslider").removeClass("btn-success");
				$("#"+tabId+" .btnslider").addClass("btn-warning");
			}else{
				$("#"+tabId+" .btnslider").removeClass("btn-warning");
				$("#"+tabId+" .btnslider").addClass("btn-success");
			}
			if(quotas.loading == 1) return;
			
			quotas.ajaxCount = 5;
			var datas = [];
			var datasyy = [];
			var datassort = [];
			//查询指标数据,本期和管理目标
			var p1 = drgUI.setAjaxData(tabId);
			p1['monitorType']='dep';
			ajaxRequest("Base", p1, function(data){
				datas = data;
				if(compareType=='none'){//如果比较类型为无，则不获取比较值
					p1.isGetCc=0;
				}
				p1.compareType = compareType;
				ajaxRequest(quotas.quotaCode_1, p1, function(data, quotaCode){
					mergeListcc(datas, data,'ccode','',quotaCode);
					quotas.ajaxCount--;
				})
				ajaxRequest(quotas.quotaCode_2, p1, function(data, quotaCode){
					mergeListcc(datas, data,'ccode','',quotaCode);
					quotas.ajaxCount--;
				});

                var pTemp = jQuery.extend(true, {}, p1);
                pTemp.isGetCc=0;
                ajaxRequest(quotas.quotaCode_3, pTemp, function(data, quotaCode){
                    for(var n in data){
                        datas[n]['symbolValue']=data[n].QuotaValue;//决定散点图点的大小的值
                    }
                    quotas.ajaxCount--;
                });
			});
			//查询指标数据,上期和管理目标
			var p2 =  drgUI.setAjaxData(tabId);
			var dateFrom = addMonth(p2.dateFrom, -1);
			var dateTo = addMonth(p2.dateTo, -1);
			p2.dateFrom = dateFrom;
			p2.dateTo = dateTo;
			p2['monitorType']='dep';
			ajaxRequest("Base", p2, function(data){
				datasyy = data;
				p2.compareType = compareType;
				if(compareType=='none'){//如果比较类型为无，则不获取比较值
					p2.isGetCc=0;
				}
				ajaxRequest(quotas.quotaCode_1, p2, function(data, quotaCode){
					mergeListcc(datasyy, data,'ccode','',quotaCode);
					quotas.ajaxCount--;
				})
				ajaxRequest(quotas.quotaCode_2, p2, function(data, quotaCode){
					mergeListcc(datasyy, data,'ccode','',quotaCode);
					quotas.ajaxCount--;
				})
			});
			//等待数据返回
			var timer = setInterval(function(){
				if(quotas.ajaxCount==0){
					clearInterval(timer);
					datas = mergeList(datas, datasyy,'ccode','yy');
					//数据处理
					var config = dataSolve(datas, quotas);
					//本期散点图
					quotas.config = config;
					quotas.data = datas;
					//执行排名算法,进行由好到坏的排序
					datasort = orderScatterData(quotas, datas);
					quotas.datasort = datasort;
					loadScatterChart1(quotas);
					loadQuadrantTable1(quotas, datas);
					quotas.loading = 1;
				}
			}, 500);
		});
		if(o==0) str.find("a").click();
	}
	//指标变化幅度按钮点击
	$("#"+tabId+" .btnslider").click(function(){
		var index = $(this).parent().find("li.active").find("a").attr("data-index");
		var quotas = quotass[index];
		var datasort = quotas.datasort;
		
		if($(this).hasClass("btn-success")){
			loadScatterChart2(datasort, quotas);
			$(this).removeClass("btn-success");
			$(this).addClass("btn-warning");
			quotas.chartType=0;
		}else{
			loadScatterChart1(quotas);
			loadQuadrantTable1(quotas, quotas.data)
			$(this).removeClass("btn-warning");
			$(this).addClass("btn-success");
			quotas.chartType=1;
		}
	});
		
	//处理数据,拼装echarts
	function dataSolve(datas, quotas){
		var xdirection = quotas.quotaDirection_1?quotas.quotaDirection_1:1;
		var ydirection = quotas.quotaDirection_2?quotas.quotaDirection_2:1;
		var xmin = 999999999;
		var xmax = -999999999;
		var ymin = 999999999;
		var ymax = -999999999;
		var symbolValueArray=[];
		for(var o in datas){
			symbolValueArray.push(datas[o].symbolValue);//决定散点图点的大小的值
			var quotaValue1 = datas[o][quotas.quotaCode_1];
			var quotaValue2 = datas[o][quotas.quotaCode_1+"cc"];
			if((quotaValue1||(compareType=='none'&&quotaValue1==0)) && (quotaValue2||(compareType=='none'&&quotaValue2==0))){
				var x = quotaValue1 - quotaValue2;
				datas[o].x = x;
			}
			//本期实际值
            datas[o].xValue = quotaValue1;
			
			var quotaValue3 = datas[o][quotas.quotaCode_2];
			var quotaValue4 = datas[o][quotas.quotaCode_2+"cc"];
			if((quotaValue3||(compareType=='none'&&quotaValue3==0)) && (quotaValue4||(compareType=='none'&&quotaValue4==0))){
				var y = quotaValue3 - quotaValue4;
				datas[o].y = y;
			}
			//本期实际值
            datas[o].yValue = quotaValue3;
			
			var quotaValue5 = datas[o][quotas.quotaCode_1+"yy"];
			var quotaValue6 = datas[o][quotas.quotaCode_1+"ccyy"];
			if((quotaValue5||(compareType=='none'&&quotaValue5==0)) && (quotaValue6||(compareType=='none'&&quotaValue6==0))){
				var x = quotaValue5 - quotaValue6;
				datas[o].x1 = x;
			}
			
			var quotaValue7 = datas[o][quotas.quotaCode_2+"yy"];
			var quotaValue8 = datas[o][quotas.quotaCode_2+"ccyy"];
			if((quotaValue7||(compareType=='none'&&quotaValue7==0)) && (quotaValue8||(compareType=='none'&&quotaValue8==0))){
				var y = quotaValue7 - quotaValue8;
				datas[o].y1 = y;
			}
			//当比较类型为无时，且选择时间消耗指数和费用消耗指数页签时，选（1,1）为坐标原点
			var k=0; 
			if(compareType=='none' && quotas.quotaCode_1=='TimeEff' && quotas.quotaCode_2=='FeeEff'){
				k=1;
			}
			
			if(typeof(datas[o].x)!="undefined" && typeof(datas[o].y)!="undefined"){
				if(datas[o].x>=k && datas[o].y>=k){
					datas[o].quadrant = 1;
					datas[o].color = '#f05a72';
				}else if(datas[o].x>k && datas[o].y<k){
					datas[o].quadrant = 4;
					datas[o].color = '#fed503';
				}else if(datas[o].x<k && datas[o].y>k){
					datas[o].quadrant = 2;
					datas[o].color = '#5bc0de';
				}else{
					datas[o].quadrant = 3;
					datas[o].color = '#66cc66';
				}
				if(datas[o].x<xmin)
				{xmin = datas[o].x;}
				if(datas[o].x>xmax)
				{ xmax = datas[o].x;}
				if(datas[o].y<ymin)
				{ ymin = datas[o].y;}
				if(datas[o].y>ymax)
				{ ymax = datas[o].y;}
				datas[o].x = datas[o].x.toFixed(2);//改为保留两位小数
				if(String(datas[o].y).split(".").length>1){
					datas[o].y = datas[o].y.toFixed(2);
				}
			}
			if(typeof(datas[o].x1)!="undefined" && typeof(datas[o].y1)!="undefined"){
				
				if(datas[o].x1<xmin)
				{xmin = datas[o].x1;}
				if(datas[o].x1>xmax)
				{ xmax = datas[o].x1;}
				if(datas[o].y1<ymin)
				{ ymin = datas[o].y1;}
				if(datas[o].y1>ymax)
				{ ymax = datas[o].y1;}
				
				datas[o].x1 = datas[o].x1.toFixed(2);//改为保留两位小数
				if(String(datas[o].y1).split(".").length>1){
					datas[o].y1 = datas[o].y1.toFixed(2);
				}
			}
		}
		//排序求最大最小值
		symbolValueArray.sort(function(a,b){return a-b;});
		var symbolValueMin=symbolValueArray[0];
		var symbolValueMax=symbolValueArray[symbolValueArray.length-1];

		xmin = Math.floor(xmin-0.2*Math.abs(xmin));
		ymin = Math.floor(ymin-0.2*Math.abs(ymin));
		xmax = Math.ceil(xmax+0.2*Math.abs(xmax));
		ymax = Math.ceil(ymax+0.2*Math.abs(ymax));
		var config = {"xmin":xmin,"xmax":xmax,"ymin":ymin,"ymax":ymax,symbolValueMin:symbolValueMin,symbolValueMax:symbolValueMax}
		return config;
	}
	//散点图
	function loadScatterChart1(quotas){
		var hospValue="";
		if(quotas.data!=undefined && quotas.data.length>0){
			if(quotas.quotaCode_1=="AvgDays"){
			hospValue="("+quotas.data[0].AvgDayscc+","+quotas.data[0].AvgFeecc+")";
			}else if(quotas.quotaCode_1=="AvgFee"){
				hospValue="("+quotas.data[0].AvgFeecc+","+quotas.data[0].DrugRatiocc+")";
			}else if(quotas.quotaCode_1=="CMI"){
				hospValue="("+quotas.data[0].CMIcc+","+quotas.data[0].DRGCountcc+")";
			}else{
				hospValue="("+quotas.data[0].TimeEffcc+","+quotas.data[0].FeeEffcc+")";
			}
		}

		var allGroupDayFeeChartData = [{"desc":"本期","data":quotas.data}];
		var sAxisDesc = quotas.quotaName_1.length>5?quotas.quotaName_1.substring(0,4)+"\n"+quotas.quotaName_1.substring(4):quotas.quotaName_1;
		var xyAx = {"xAxis":{"desc":sAxisDesc+"(0)"},"yAxis":{"desc":quotas.quotaName_2+"(0)"}};
		var compareName = '';
		if (compareType == "year") {
			compareName = "与同期差值";
		} else if (compareType == "month") {
			compareName = "与上期差值";
		} else if (compareType == "manage") {
			compareName = "与绩效差值";
		} else if (compareType == "std") {
			compareName = "与标杆差值";
		}else if (compareType == "hosp") {
			compareName = "与院内均值"+hospValue+"差值";
		}
		var chartParams=quotas.config;
		//散点图大小处理函数
		var symboSizeFunc=function(data){
			var region = chartParams.symbolValueMax-chartParams.symbolValueMin;
			if(region == 0){
				region = 1;
			}
			//归一化处理
			return (((data[2]-chartParams.symbolValueMin)/region)*2+1)*10;
		}
		chartParams.symboSizeFunc=symboSizeFunc;
		chartParams.isDataZoom=true;
		//散点图提示框处理函数
		chartParams.formatterFunc=function (params) {
			if(params.componentType == "markLine")
			{//如果是标记线
				return params.name + " " +params.data.value;
			}
	    	//修改散点图悬浮框显示样式(黑框)
	    	var str="";
	    	str+=params.name+ "<br/>" +"("+params.data.value[0]+","+params.data.value[1]+")";
            str+="<br/>" +"实际值 ( "+params.data.xValue+", "+params.data.yValue+" )";//实际值
            if(chartParams.symbolValueMin&&chartParams.symbolValueMin){//如果添加总权重 用于求散点图点的大小，则在散点图中添加总权重的提示信息
	    		str+="<br/>总权重:" +params.data.value[2];
		    }
	    	return str;
    	};
    	var markline = null;
    	if(compareType != "none"){//比较对象不为 [无] 时
    		//散点图点击事件
    		chartParams.callBack_click=function(value){
    			var data = value.data;
    			var depCode = data.code;
    			var depName = data.name;
    			var p = drgUI.setAjaxData(tabId);//页面参数
    			p.pardepCode = depCode;
    			p.depCode = depCode;
    			p.depName = depName;
    			p.compareType=compareType;
				//二级科室的分析页面中，病组结构分析页面的超链接-- CMI和DRGs组数跳转到医政角色病组结构分析页面，其他指标对跳转到医保角色病组结构分析页面
				p.patientGroupAnalysisPage = 'yibao';
    			if(quotas.quotaCode_1=="AvgDays" && quotas.quotaCode_2=="AvgFee"){
    				//根据数组的depcode找到该数组的某个指标项值
    				p.typeOne=findQuotasValueByDepCode(quotas,depCode,"AvgDayscc");
    				p.typeTwo=findQuotasValueByDepCode(quotas,depCode,"AvgFeecc");
    				openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_AvgDaysAvgFee.jsp', '平均住院日和次均费用'+"|"+depName,'depQuadrantAnalysis-AvgDaysAvgFee', 'depQuadrantAnalysis-AvgDaysAvgFee',p);
    			}
    			if(quotas.quotaCode_1=="AvgFee" && quotas.quotaCode_2=="DrugRatio"){
    				p.typeOne=findQuotasValueByDepCode(quotas,depCode,"AvgFeecc");
    				p.typeTwo=findQuotasValueByDepCode(quotas,depCode,"DrugRatiocc");
    				openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_AvgFeeDrugRatio.jsp', '次均费用和药占比'+"|"+depName,'depQuadrantAnalysis_AvgFeeDrugRatio', 'depQuadrantAnalysis-AvgFeeDrugRatio',p);
    			}
    			if(quotas.quotaCode_1=="TimeEff" && quotas.quotaCode_2=="FeeEff"){
    				p.typeOne=findQuotasValueByDepCode(quotas,depCode,"TimeEffcc");
    				p.typeTwo=findQuotasValueByDepCode(quotas,depCode,"FeeEffcc");
    				if((data.value[0]>0&&data.value[1]>0) || (data.value[0]<0&&data.value[1]<0)){
    					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff13.jsp', '时间消耗指数和费用消耗指数'+"|"+depName,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
    				}else if(data.value[0]<0&&data.value[1]>0){
    					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff4.jsp', '时间消耗指数和费用消耗指数'+"|"+depName,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
    				}else if(data.value[0]>0&&data.value[1]<0){
    					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff2.jsp', '时间消耗指数和费用消耗指数'+"|"+depName,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
    				}
    			}
    			if(quotas.quotaCode_1=="CMI" && quotas.quotaCode_2=="DRGCount"){
    				p.patientGroupAnalysisPage = 'yizheng';//CMI和DRGs组数跳转到医政角色病组结构分析页面
    				p.typeOne=findQuotasValueByDepCode(quotas,depCode,"CMIcc");
    				p.typeTwo=findQuotasValueByDepCode(quotas,depCode,"DRGCountcc");
    				openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_CMIDRGCount.jsp', 'CMI值和DRGs组数'+"|"+depName,'depQuadrantAnalysis_CMIDRGCount', 'depQuadrantAnalysis-CMIDRGCount',p);
    			}
    		}
		}
    	else{
    		chartParams.cursor = "default";
    		if(quotas.quotaCode_1=="TimeEff" && quotas.quotaCode_2=="FeeEff"){
    			markline = {animation:false,lineStyle: {normal: {width:1,color:"#000",type: 'solid'}},symbol:'none',data:[{xAxis: 1,label:{normal:{show:true,formatter:function(){return '费用消耗指数';}}}},{yAxis: 1,label:{normal:{show:true,formatter:function(){return '时间消耗指数';}}}}]};
    			xyAx.xAxis["axisLine"]={show:false};
    			xyAx.xAxis["desc"]="";
    			xyAx.yAxis["axisLine"]={show:false};
    			xyAx.yAxis["desc"]="";
    		}
		}

		scatterChartsWithLine($("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-chart"),allGroupDayFeeChartData,xyAx,quotas.quotaName_1+"和"+quotas.quotaName_2+compareName+"象限分析图",markline,chartParams);
	}
	//四象限table方法
	function loadQuadrantTable1(quotas, datas){
		if(compareType=='none' &&quotas.quotaCode_1=='TimeEff' && quotas.quotaCode_2=='FeeEff'){
			var xmin = 999999999;
			var xmax = -999999999;
			var ymin = 999999999;
			var ymax = -999999999;
			for(var o in datas){
				var quotaValue1 = datas[o][quotas.quotaCode_1];
				var quotaValue2 = datas[o][quotas.quotaCode_2];
				var x = quotaValue1;
				var y = quotaValue2;
				datas[o].x = x;
				datas[o].y = y;

				if(typeof(datas[o].x)!="undefined" && typeof(datas[o].y)!="undefined"){
					if(datas[o].x>=1 && datas[o].y>=1){
						datas[o].quadrant = 1;
						datas[o].color = '#f05a72';
					}else if(datas[o].x>1 && datas[o].y<1){
						datas[o].quadrant = 4;
						datas[o].color = '#fed503';
					}else if(datas[o].x<1 && datas[o].y>1){
						datas[o].quadrant = 2;
						datas[o].color = '#5bc0de';
					}else{
						datas[o].quadrant = 3;
						datas[o].color = '#66cc66';
					}
					if(datas[o].x<xmin)
					{xmin = datas[o].x;}
					if(datas[o].x>xmax)
					{ xmax = datas[o].x;}
					if(datas[o].y<ymin)
					{ ymin = datas[o].y;}
					if(datas[o].y>ymax)
					{ ymax = datas[o].y;}
					datas[o].x = datas[o].x.toFixed(2);//改为保留两位小数
					if(String(datas[o].y).split(".").length>1){
						datas[o].y = datas[o].y.toFixed(2);
					}
				}
			}
		}
		$("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").each(function(i, n){
			$(n).find("td").eq(1).html("");
		})
		for(var o in datas){
			var data = datas[o];
			var dep = null;
			if(compareType=='none'  && quotas.quotaCode_1!='TimeEff' && quotas.quotaCode_2!='FeeEff')
			{	
				dep = $('<span>'+data.ddesc+'</span>');
			}else{
				dep = $('<span><a href="javascript:void(0);">'+data.ddesc+'</a></span>');
			}

			dep.data(data);
			dep.unbind("click");
			dep.bind("click", function(){
				var p = drgUI.setAjaxData(tabId);//页面参数
				var d = $(this).data();
				p.pardepCode = d.ccode;
				p.depCode = d.ccode;
				p.depName = d.ddesc;
				p.compareType=compareType;
				//二级科室的分析页面中，病组结构分析页面的超链接-- CMI和DRGs组数跳转到医政角色病组结构分析页面，其他指标对跳转到医保角色病组结构分析页面
				p.patientGroupAnalysisPage = 'yibao';
				if(quotas.quotaCode_1=="AvgDays" && quotas.quotaCode_2=="AvgFee"){
					//根据数组的depcode找到该数组的某个指标项值
    				p.typeOne=findQuotasValueByDepCode(quotas,d.ccode,"AvgDayscc");
    				p.typeTwo=findQuotasValueByDepCode(quotas,d.ccode,"AvgFeecc");
					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_AvgDaysAvgFee.jsp', '平均住院日和次均费用'+"|"+d.ddesc,'depQuadrantAnalysis-AvgDaysAvgFee', 'depQuadrantAnalysis-AvgDaysAvgFee',p);
				}
				if(quotas.quotaCode_1=="AvgFee" && quotas.quotaCode_2=="DrugRatio"){
					p.typeOne=findQuotasValueByDepCode(quotas,d.ccode,"AvgFeecc");
    				p.typeTwo=findQuotasValueByDepCode(quotas,d.ccode,"DrugRatiocc");
					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_AvgFeeDrugRatio.jsp', '次均费用和药占比'+"|"+d.ddesc,'depQuadrantAnalysis_AvgFeeDrugRatio', 'depQuadrantAnalysis-AvgFeeDrugRatio',p);
				}
				if(quotas.quotaCode_1=="TimeEff" && quotas.quotaCode_2=="FeeEff"){
					p.typeOne=findQuotasValueByDepCode(quotas,d.ccode,"TimeEffcc");
    				p.typeTwo=findQuotasValueByDepCode(quotas,d.ccode,"FeeEffcc");
					if(d.quadrant==1 || d.quadrant==3){
						openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff13.jsp', '时间消耗指数和费用消耗指数'+"|"+d.ddesc,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
					}else if(d.quadrant==2){
						openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff2.jsp', '时间消耗指数和费用消耗指数'+"|"+d.ddesc,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
					}else if(d.quadrant==4){
						openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff4.jsp', '时间消耗指数和费用消耗指数'+"|"+d.ddesc,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
					}
				}
				if(quotas.quotaCode_1=="CMI" && quotas.quotaCode_2=="DRGCount"){
					p.patientGroupAnalysisPage = 'yizheng';//CMI和DRGs组数跳转到医政角色病组结构分析页面
					p.typeOne=findQuotasValueByDepCode(quotas,d.ccode,"CMIcc");
    				p.typeTwo=findQuotasValueByDepCode(quotas,d.ccode,"DRGCountcc");
					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_CMIDRGCount.jsp', 'CMI值和DRGs组数'+"|"+d.ddesc,'depQuadrantAnalysis_CMIDRGCount', 'depQuadrantAnalysis-CMIDRGCount',p);
				}
			})
			$("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").eq(data.quadrant-1).find("td").eq(1).append(dep);
			$("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").eq(data.quadrant-1).find("td").eq(1).append('<span>、</span>');
		}
		$("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").each(function(){
			if($(this).find("td").eq(1).html()!=''){
				$(this).find("td").eq(1).find('span').last().html('');
			}
		});
		
	}
	//散点线图
	function loadScatterChart2(dataf, quotas){
		var scatterChartData = [];
		var xAxis={"desc":quotas.quotaName_1+"(0)"};
		var yAxis={"desc":quotas.quotaName_2+"(0)"};
		for(var o in dataf){
			var data = dataf[o];
			if(data.x && data.y && data.x1 && data.y1 && data.per){
//				scatterChartData[0].data.push({"desc":data.ddesc,"xdata":data.x,"ydata":data.y});//本期
//				scatterChartData[1].data.push({"desc":data.ddesc,"xdata":data.x1,"ydata":data.y1});//上期
				var dataIndex=Number(data.index)+1;
				scatterChartData.push({"coords":[[data.x1,data.y1],[data.x, data.y]], value:data.per,index:dataIndex,code:data.ccode,desc:data.ddesc,quadrant:data.quadrant});
			}
		}
		var chartParams={visualMap:true,isDataZoom:false};
		chartParams.callback_click = function(value){
			var data = value.data;
			var depCode = data.code;
			var depName = data.desc;
			var p = drgUI.setAjaxData(tabId);//页面参数
			p.pardepCode = depCode;
			p.depCode = depCode;
			p.depName = depName;
			p.compareType=compareType;
			//二级科室的分析页面中，病组结构分析页面的超链接-- CMI和DRGs组数跳转到医政角色病组结构分析页面，其他指标对跳转到医保角色病组结构分析页面
			p.patientGroupAnalysisPage = 'yibao';
			if(quotas.quotaCode_1=="AvgDays" && quotas.quotaCode_2=="AvgFee"){
				//根据数组的depcode找到该数组的某个指标项值
				p.typeOne=findQuotasValueByDepCode(quotas,depCode,"AvgDayscc");
				p.typeTwo=findQuotasValueByDepCode(quotas,depCode,"AvgFeecc");
				openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_AvgDaysAvgFee.jsp', '平均住院日和次均费用'+"|"+depName,'depQuadrantAnalysis-AvgDaysAvgFee', 'depQuadrantAnalysis-AvgDaysAvgFee',p);
			}
			if(quotas.quotaCode_1=="AvgFee" && quotas.quotaCode_2=="DrugRatio"){
				p.typeOne=findQuotasValueByDepCode(quotas,depCode,"AvgFeecc");
				p.typeTwo=findQuotasValueByDepCode(quotas,depCode,"DrugRatiocc");
				openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_AvgFeeDrugRatio.jsp', '次均费用和药占比'+"|"+depName,'depQuadrantAnalysis_AvgFeeDrugRatio', 'depQuadrantAnalysis-AvgFeeDrugRatio',p);
			}
			if(quotas.quotaCode_1=="TimeEff" && quotas.quotaCode_2=="FeeEff"){
				p.typeOne=findQuotasValueByDepCode(quotas,depCode,"TimeEffcc");
				p.typeTwo=findQuotasValueByDepCode(quotas,depCode,"FeeEffcc");
				if(data.quadrant==1 || data.quadrant==3){
					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff13.jsp', '时间消耗指数和费用消耗指数'+"|"+depName,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
				}else if(data.quadrant==2){
					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff2.jsp', '时间消耗指数和费用消耗指数'+"|"+depName,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
				}else if(data.quadrant==4){
					openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_TimeEffFeeEff4.jsp', '时间消耗指数和费用消耗指数'+"|"+depName,'depQuadrantAnalysis_TimeEffFeeEff', 'depQuadrantAnalysis-TimeEffFeeEff',p);
				}
			}
			if(quotas.quotaCode_1=="CMI" && quotas.quotaCode_2=="DRGCount"){
				p.patientGroupAnalysisPage = 'yizheng';//CMI和DRGs组数跳转到医政角色病组结构分析页面
				p.typeOne=findQuotasValueByDepCode(quotas,depCode,"CMIcc");
				p.typeTwo=findQuotasValueByDepCode(quotas,depCode,"DRGCountcc");
				openTab('/pages/yizheng/quadrantAnalysis/depQuadrantAnalysis_CMIDRGCount.jsp', 'CMI值和DRGs组数'+"|"+depName,'depQuadrantAnalysis_CMIDRGCount', 'depQuadrantAnalysis-CMIDRGCount',p);
			}
		}
		chartParams.callback_range = function(param){
			var range_s = param.selected[0];
			var range_e = param.selected[1];
			
			var datas1 = [];
			var length = dataf.length;
			range_s = range_s*length/100;
			range_e = range_e*length/100;
			range_e = range_e<length?range_e:length-1;
			for(var o=Math.ceil(range_s); o<=range_e; o++){
				var data = dataf[o];
				datas1.push(data);
				
			}
			loadQuadrantTable1(quotas, datas1);
		};
		chartParams.formatterFunc=function (params) {
        	var str="";
        	var index=Number(params.data.index);
        	str+=params.data.desc+":上期("+params.data.coords[0][0]+","+params.data.coords[0][1]+")<br>"+params.data.desc+":本期("+params.data.coords[1][0]+","+params.data.coords[1][1]+")<br>排名:"+index;        	
        	return str;
    	};
		var compareName = '';
		if (compareType == "year") {
			compareName = "同期";
		} else if (compareType == "month") {
			compareName = "上期";
		} else if (compareType == "manage") {
			compareName = "绩效";
		} else if (compareType == "std") {
			compareName = "标杆";
		}else if (compareType == "hosp") {
			compareName = "院内均值";
		}
		if(quotas.config && quotas.config.xmin!=undefined){
			xAxis.xmin = quotas.config.xmin;
		}
		if(quotas.config && quotas.config.xmax!=undefined){
			xAxis.xmax = quotas.config.xmax;
		}
		if(quotas.config && quotas.config.ymin!=undefined){
			yAxis.ymin = quotas.config.ymin;
		}
		if(quotas.config && quotas.config.ymax!=undefined){
			yAxis.ymax = quotas.config.ymax;
		}
		linesChartBasic($("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-chart"),scatterChartData,xAxis,yAxis,'',quotas.quotaName_1+"和"+quotas.quotaName_2+"与"+compareName+"差值象限分析图",'', chartParams);
		chartParams.callback_range({selected:[80,100]});
	}
	/**
	 * 获取数据回调函数
	 */
	function ajaxRequest(quotaCode, param, callback){
		param.quotaCode = quotaCode;
		$.post(contextPath + "/DrgsIndexCal/indexCal.dhc", param).done(function(result){
			var data=[];
			if(result.success && result.data){
				data=result.data;
			}
			callback(data, quotaCode);
		});
	}
	//根据数组的depcode找到该数组的某个指标项值
	function findQuotasValueByDepCode(quotas,depCode,quotaCode){
		quotas=quotas.data;
		if(quotas.length>0){
			var j=0;
			for( var i = 0; i <quotas.length; i++){
				j++;
				//找到depCode返回指标项的值
				if(quotas[i].ccode==depCode){
					return quotas[i][quotaCode];
				}
				//防止掉入死循环
				if(j>quotas.length){
					return "-";
				}
			}
		}else{
			return "-";
		}
	}
	paramTabPage[tabId].loading=1;
});


/**
xdata x轴数据
ydata y轴数据
xstd x轴标杆
ystd y轴标杆
xdirection x指标方向 1正向 -1负向
xdirection y指标方向 1正向 -1负向
*/
function orderScatterData(quotas, datas){
	var xdirection = quotas.quotaDirection_1?quotas.quotaDirection_1:1;
	var ydirection = quotas.quotaDirection_2?quotas.quotaDirection_2:1;
	var datasort = [];
	for(var i=0;i<datas.length;i++){
		var data = datas[i];
		var quotaValueRx = 0;
		var quotaValueRy = 0;
		if(data[quotas.quotaCode_1]!=null && data[quotas.quotaCode_1+"cc"]!=null&&data[quotas.quotaCode_1+"cc"]>0 
		 && data[quotas.quotaCode_1+"yy"]!=null && data[quotas.quotaCode_1+"ccyy"]!=null&&data[quotas.quotaCode_1+"ccyy"]>0 
		 && data[quotas.quotaCode_2]!=null && data[quotas.quotaCode_2+"cc"]!=null&&data[quotas.quotaCode_2+"cc"]>0 
		 && data[quotas.quotaCode_2+"yy"]!=null && data[quotas.quotaCode_2+"ccyy"]!=null&&data[quotas.quotaCode_2+"ccyy"]>0){
			try{
				quotaValueRx = data[quotas.quotaCode_1]/data[quotas.quotaCode_1+"cc"] - data[quotas.quotaCode_1+"yy"]/data[quotas.quotaCode_1+"ccyy"];
				quotaValueRy = data[quotas.quotaCode_2]/data[quotas.quotaCode_2+"cc"] - data[quotas.quotaCode_2+"yy"]/data[quotas.quotaCode_2+"ccyy"];
				var l = Math.sqrt(Math.pow(quotaValueRx,2)+Math.pow(quotaValueRy,2));
				if(l==Infinity || l==-Infinity){
					data.l = 0;
				}else{
					if(xdirection*quotaValueRx>0&&ydirection*quotaValueRy>0) {
						// 变好
						data.l = l;
					} else {
						// 变差
						data.l = -l;
					}
				}
				datasort.push(data);
			}catch(e){
			}
		}
	}
	datasort.sort(function(a,b){return b.l-a.l});// 降序
	var index = 0;// 排名
	var length = datasort.length;
	for(var o in datasort){
		var data = datasort[o];
		var per = (index/length*100).toFixed(2);
		data.per = per;// 名次
		data.index=index;
		index++;
	}
	return datasort;
}

//将list2中的内容覆盖更新到list1中，返回list1,quotaCode为更新的指标名
function mapList(list1, list2, quotaCode, tail){
	if(!tail) tail = "cc";
	var i=0;
	var j=0;
	var iMax=list1.length;
	var jMax=list2.length;
	for(i=0; i<iMax; i++){
		var k=j;
		var map1 = list1[i];
		var ccode1 = map1["ccode"]?map1["ccode"]:"";
		while(true){
			if(k==jMax) break;
			var map2 = list2[k];
    		var ccode2 = map2["ccode"]?map2["ccode"]:"";
			if(ccode2 == ccode1 ){
				 for(var dataKey in map2)   {    
					 map1[dataKey] = map2[dataKey];	
				 }
				 map1[quotaCode]=map1["QuotaValue"];
				 var quotaCodecc=quotaCode+tail;
				 map1[quotaCodecc]=map1["QuotaValuecc"]==undefined?0:map1["QuotaValuecc"];
				 delete(map1["QuotaValue"]);
				 delete(map1["QuotaValuecc"]);
				 j++;
				 break;
			}
			k++;
		}
	}
	return list1;
}
